#!/bin/bash

echo "=== Uploading Route Files One by One ==="

# Array of route files
files=("auth.js" "users.js" "menu.js" "orders.js" "coupons.js" "payments.js" "admin.js")

for file in "${files[@]}"; do
    echo "Uploading $file..."
    scp -o ConnectTimeout=30 "temp-routes/$file" "root@47.237.10.129:/opt/cumrbull/backend/src/routes/"
    if [ $? -eq 0 ]; then
        echo "✓ $file uploaded successfully"
        # Verify file exists on server
        ssh -o ConnectTimeout=10 root@47.237.10.129 "ls -la /opt/cumrbull/backend/src/routes/$file" 2>/dev/null && echo "✓ $file verified on server"
    else
        echo "✗ Failed to upload $file"
    fi
    echo "---"
done

echo "=== Upload Complete ==="
echo "Verifying all files on server..."
ssh -o ConnectTimeout=15 root@47.237.10.129 'ls -la /opt/cumrbull/backend/src/routes/ && echo "Total JS files: $(ls -1 /opt/cumrbull/backend/src/routes/*.js 2>/dev/null | wc -l)"'